%% Setting Directory & Paths
clear
cd /yourpath/FinalReplicationPackage/output/figures/
addpath('/yourpath/FinalReplicationPackage/data/simulations')

alpha_array = [-1:0.1:2]
gamma = 0.484 

for xn = 1:length(alpha_array)
    filename = sprintf('alpha=%.1f_gamma=%.3f_weather.mat', alpha_array(xn), gamma);
    load(filename)
    pct_above95_array(xn) = aa_pct_above95
    pct_belowours_array(xn) = aa_pct_belowours
    rho_eR_mean_array(xn) = rho_eR_mean
    rho_eP_mean_array(xn) = rho_eP_mean
    rho_dR_mean_array(xn) = abs(rho_dR_mean)
    rho_dP_mean_array(xn) = rho_dP_mean
    rho_de_mean_array(xn) = abs(rho_de_mean)
end

gamma = 0.692 
for xn = 1:length(alpha_array)
    filename = sprintf('alpha=%.1f_gamma=%.3f_weather.mat', alpha_array(xn), gamma);
    load(filename)
    pct_above95_array2(xn) = aa_pct_above95
    pct_belowours_array2(xn) = aa_pct_belowours
    rho_eR_mean_array2(xn) = rho_eR_mean
    rho_eP_mean_array2(xn) = rho_eP_mean
    rho_dR_mean_array2(xn) = abs(rho_dR_mean)
    rho_dP_mean_array2(xn) = rho_dP_mean
    rho_de_mean_array2(xn) = abs(rho_de_mean)
end


%% Plot 1 (pval < 0.942)
    clf
   
    f = plot(alpha_array, pct_belowours_array, '-o', 'MarkerSize', 10, 'LineWidth', 1.5, color="r");
    hold on
    plot(alpha_array, pct_belowours_array2, '-o', 'MarkerSize', 10, 'LineWidth', 1.5, color="b")
    xlabel("\alpha (Share of action-based persistence)");
    ylabel("Share of cases sargan p-value<0.942");
    %ttl = title("Share of cases sargan p-value<0.942")
    %subtitle(sprintf("(Experimental Sample)", gamma))
    lgd = legend('\gamma = 0.484', '\gamma = 0.692', 'Location', 'SouthWest')
    fontsize(lgd,11,'points')
    %fontsize(ttl,12,'points')

    if gamma == 0.692
        ylim([0 1])
    else
        ylim([0 1])
    end
    
    filename = sprintf('sargan_plot_below_ours-bothgammas.png', gamma);
    saveas(f,filename);

%% Plot 2 (pval < 0.05)
    clf
   
    f = plot(alpha_array, pct_above95_array, '-o', 'MarkerSize', 10, 'LineWidth', 1.5, color="r");
    hold on
    plot(alpha_array, pct_above95_array2, '-o', 'MarkerSize', 10, 'LineWidth', 1.5, color="b")
    xlabel("\alpha (Share of action-based persistence)");
    ylabel("Share of cases sargan p-value<0.05");
    %ttl = title("Share of cases sargan p-value<0.05")
    %subtitle(sprintf("(Experimental Sample)", gamma))
    lgd = legend('\gamma = 0.484', '\gamma = 0.692', 'Location', 'SouthWest')
    fontsize(lgd,11,'points')
    %fontsize(ttl,12,'points')

    if gamma == 0.692
        ylim([0 1])
    else
        ylim([0 1])
    end
    
    filename = sprintf('sargan_plot_below_pt05-bothgammas.png', gamma);
    saveas(f,filename);


    
